#include "CAnimationManager.h"

CAnimationManager::CAnimationManager()
{
	m_unNumAnimations = 0;
}

CAnimationManager::~CAnimationManager()
{
	
}
	
CAnimationManager* CAnimationManager::GetInstance()
{
	static CAnimationManager instance;
	return &instance;
}
	
void CAnimationManager::Init()
{
	
}
void CAnimationManager::Shutdown()
{

}

bool CAnimationManager::AddAnimation(const char* szFileName)
{
	for(unsigned int i = 0; i < m_unNumAnimations; ++i)
	{
		if(strcmp(m_Animations[i]->GetName(), szFileName) == 0)
			return false;
	}

	CAnimation* pAnim = new CAnimation();
	std::string path = "resource/animations/";
	path += szFileName;
	pAnim->LoadAnimation(path.c_str());
	m_Animations.push_back(pAnim);

	m_unNumAnimations++;

	return true;
}

bool CAnimationManager::AddAnimation(CAnimation* pAnim)
{
	for(unsigned int i = 0; i < m_unNumAnimations; ++i)
	{
		if(strcmp(m_Animations[i]->GetName(), pAnim->GetName()) == 0)
			return false;
	}

	m_Animations.push_back(pAnim);
	m_unNumAnimations++;

	return true;
}

bool CAnimationManager::RemoveAnimation(const char* szFileName)
{
	for(unsigned int i = 0; i < m_unNumAnimations; ++i)
	{
		if(strcmp(m_Animations[i]->GetName(), szFileName) == 0)
		{
			//CAnimation* pAnim = m_Animations[i];
			m_Animations.erase(m_Animations.begin() + i);
			m_unNumAnimations--;
			return true;
		}
	}

	return false;
}

bool CAnimationManager::RemoveAnimation(unsigned int unIndex)
{
	if(unIndex >= m_unNumAnimations)
		return false;

	m_Animations.erase(m_Animations.begin() + unIndex);
	m_unNumAnimations--;
	
	return true;
}

CAnimation* CAnimationManager::GetAnimation(const char* szAnimName)
{
	for(unsigned int i = 0; i < m_unNumAnimations; ++i)
	{
		if(strcmp(szAnimName, m_Animations[i]->GetName()) == 0)
			return m_Animations[i];
	}

	return NULL;
}

CAnimation* CAnimationManager::GetAnimation(unsigned int unIndex)
{
	if(unIndex >= m_unNumAnimations)
		return NULL;

	return m_Animations[unIndex];
}

unsigned int CAnimationManager::GetAnimationIndex(const char* szAnimName)
{
	for(unsigned int i = 0; i < m_unNumAnimations; ++i)
	{
		if(strcmp(szAnimName, m_Animations[i]->GetName()) == 0)
			return i;
	}

	return -1;
}